#ifndef _COWSERVICE_COWSERVICE_H_
#define _COWSERVICE_COWSERVICE_H_

#include <map>
using std::map;
#include <list>
using std::list;
#include <vector>
using std::vector;
#include <string>
using std::string;

#include "xml.h"
#include "queue.h"
#include "socket.h"
#include "singleton.h"
#include "mysqlmgr.h"

#define CREATE_SERVICE(s)	inline CCowService* Create##s(void)\
							{\
                                CCowService* v = new CCowsrv##s(); return v;\
							}

class CCowCmd
{
    CCowCmd();

public:

    CCowCmd(string method)
        : m_method(method)
    {}
    
    virtual ~CCowCmd(){}

    virtual bool ToNetPack(CXmlBuffer& outbuf);

    virtual bool ToNetPack(CXmlBlock& outblock) = 0;
    virtual bool LoadFromNetPack(CXmlBlock& inblock) = 0;

    string m_method;
};

class CCowService
{
public:

    CCowService();

    virtual ~CCowService();
    
    virtual void Initialize(CXmlBlock* inblock, CCowMysql* mysql);

    virtual bool ToNetPack(CXmlBuffer& outbuf) = 0;

protected:

    CXmlBlock* m_inblock;

    CCowMysql* m_mysql;
};

typedef CCowService* (*regsrv)();

typedef	map<string, regsrv>	creator_srv_map;

class CCowSrvFactory
{
    friend class CSingleton<CCowSrvFactory>;

    CCowSrvFactory();

public:	

    ~CCowSrvFactory(){}

    CCowService* Create(const char* name);

    creator_srv_map	m_creatormap;
};

#define sCowSrvFactory CSingleton<CCowSrvFactory>::Instance()

#define REG_SERVICE(s) m_creatormap[#s] = Create##s;

#endif //_COWSERVICE_COWSERVICE_H_
